package com.yang.test;

import java.util.List;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.junit.Test;

public class MyProcessInstanceExecute {

	private ProcessEngine processEngine = Configuration.getProcessEngine();

	// 1.启动流程实例
	@Test
	public void testStartProcessInsanece() {
		ProcessInstance pi = processEngine.getExecutionService()//
				.startProcessInstanceByKey("test");
		System.out.println("id=" + pi.getId()//
				+ ", state=" + pi.getState()//
				+ ", processDefinitionId=" + pi.getProcessDefinitionId());
	}

	// 2.获取我的未完成的任务列表
	@Test
	public void testFindMyTaskList() {
		String userId = "员工";
		// String userId = "部门经理";
		// String userId = "总经理";

		List<Task> list = processEngine.getTaskService().findPersonalTasks(
				userId);

		System.out.println("======================【" + userId
				+ "】的任务列表=======================");

		for (Task t : list) {
			System.out.println("id=" + t.getId()//
					+ ", name=" + t.getName()//
					+ ", accignee=" + t.getAssignee()//
					+ ", reateTime=" + t.getCreateTime()
					+ ", executionId=" + t.getExecutionId());
		}
	}

	// 3.办理完一个任务
	@Test
	public void testFindMyTaskLists() {
		String taskId = "180001";
		processEngine.getTaskService().completeTask(taskId);
	}
}
